package 快速排序;

import java.util.Arrays;

public class quickssort {
    public static void quickSort(int[] array){
        quick(array,0,array.length-1);
    }
    public static void quick(int[] array,int left,int right){
        if(left>=right){
            return;
        }
        int pivot=partition(array,left,right);//找到基准
        quick(array,left,pivot-1);
        quick(array,pivot+1,right);
    }
    private static   int partition(int[] array,int start,int end){
        int tmp=array[start];
        while(start < end){
            while(start < end && array[end] >= tmp){
                end--;
            }
            //end下标遇到了小于tmp的值
            array[start]=array[end];
            while(start < end && array[start] <= tmp){
                start++;
            }
            array[end]=array[start];

        }
        array[start]=tmp;
        return start;


    }

    public static void main(String[] args) {
        int[] array={12,5,9,34,0,33,6,55};
        quickSort(array);
        System.out.println(Arrays.toString(array));
    }
}
